package com.farewell.controller;

import com.farewell.pojo.Order;
import com.farewell.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author Farewell
 * @date 2021/3/25
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAllByProductId(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum) {
        ModelAndView mv = new ModelAndView();
        PageHelper.startPage(pageNum, 10);
        List<Order> orderList = orderService.findAll();
        PageInfo<Order> pageInfo = new PageInfo<>(orderList);
        mv.addObject("pageInfo", pageInfo);
        mv.setViewName("orders-list");
        return mv;
    }

/*    @RequestMapping("save.do")
    public String saveOrUpdate(Order order, @RequestParam(defaultValue = "", value = "id") String id) {

    }*/
}
